﻿using System;
using System.Collections.Generic;
using System.Text;

namespace IntellectShop.Common
{
	public partial class TagsSet : List<string>
	{
		public int CommodityID { get; set; }

		public TagsSet()
		{
		}

		public TagsSet(int commodityID)
		{
			this.CommodityID = commodityID;
		}

		public TagsSet(int commodityID, string tags)
			: this(commodityID)
		{
			if (String.IsNullOrEmpty(tags))
				return;

			foreach (var tag in tags.Split(new char[] { ';', ',' }))
			{
				if (String.IsNullOrEmpty((tag ?? String.Empty).Trim()))
					continue;

				this.Add(tag.Trim());
			}
		}

		public override string ToString()
		{
			StringBuilder buf = new StringBuilder();
			foreach (var tag in this)
			{
				buf.AppendFormat("{0}, ", tag);
			}

			return buf.ToString().TrimEnd(new char[] { ' ', ',' });
		}
	}
}
